function getData() {
    $.ajax({
        url: 'http://localhost:3000/cart/cartt',
        type: 'get',
        dataType: 'json',
        success: function(data) {
            if (data.code) {
                let html = '';

                data.data.forEach(function(item) {
                    html += `
                            <li>    
                     
        <div class="cart_column_01">
            <i class="IGoodsItem icons icon_checked" data-checked="1"></i>
            
    <a name="p_25273_0_0_0_0_0" href="/product-25273.html" target="_blank">
        <img src=${item.img} class="product_img">
    </a>
    </div>
    <div class="cart_column_02">
    <a href="/product-25273.html" class="product_name " target="_blank">
        ${item.name}  
    </a>
            <div class="s_globaltax">
    <em>◆</em>
    <i>◆</i>
     <span>税费 = 购买单价×件数×税率</span>
     <p>据国家政策规定，本品适用于跨境综合税：9.1%
     实际结算税费请以提交订单时的税费明细为准</p>      
    </div>
    <span class="tags">直降</span> </div>
    <div class="cart_column_03">
    <span class="weight">${item.weight}kg</span>
    </div>
    <div class="cart_column_04">
    <span class="product_price">${item.price}</span>
    </div>
    <div class="cart_column_05">     <span class="product_youhuiprice">${item.youhui}</span>     
    </div>
    <div class="cart_column_06">
            <div class="product_price_modify">
        <a href="javascript:;" class="IDecNum decrease">-</a>
        <input type="text" value="1" basevalue="1" minnum="1" maxnum="99" class="IGoodsNum product_nums">
                    <a href="javascript:;" class="IIncNum increase">+</a>
    </div>
            
        </div>
    <div class="cart_column_07">
    <p class="product_total"><strong class="product_price product_priceAll">${item.price-item.youhui}</strong></p>
    </div>
    <div class="cart_column_08">
        <a href="javascript:;" class="IAddFavorites product_operation" data-bd="act:click" data-bd-event="type:goods|pos_name:%E5%95%86%E5%9F%8E_%E8%B4%AD%E7%89%A9%E8%BD%A6_%E7%A7%BB%E5%85%A5%E6%94%B6%E8%97%8F|value:25273">移入收藏</a><br>
    <a href="javascript:;" class="ICartRemove product_operation delete_shopcart" data-bd="act:click" data-bd-event="type:goods|pos_name:%E5%95%86%E5%9F%8E_%E8%B4%AD%E7%89%A9%E8%BD%A6_%E5%88%A0%E9%99%A4|value:25273">删除</a>
     </div>
    
    </li>`
                    $('.cart_goodslist').html(html);

                })
            }
            let product_youhuiprice = document.querySelectorAll('.product_youhuiprice');
            let weight = document.querySelectorAll('.weight');
            let weightArr = [];

            let weightSum = document.querySelector('.weightSum')
            let icon_checked = document.querySelectorAll('.icon_checked');
            let checkall = document.querySelector('.checkall')
            let product_price = document.querySelectorAll('.product_priceAll');
            let dec = document.querySelectorAll('.decrease');
            let inc = document.querySelectorAll('.increase');
            let num = document.querySelectorAll('.product_nums');
            let price = [];
            let product_sum = document.querySelector('.product_sum');
            let s_money_span = document.querySelector('.s_money span');
            let save = document.querySelector('.save')
            let delete_shopcart = document.querySelectorAll('.delete_shopcart');
            let product_name = document.querySelectorAll('.product_name');
            // console.log(product_name);

            // console.log(delete_shopcart);
            delete_shopcart.forEach(function(item, index) {
                item.onclick = function() {
                    // console.log(3);

                    $.ajax({
                        url: 'http://localhost:3000/cart/cartdelete',
                        type: 'get',
                        dataType: 'json',
                        data: {
                            name: product_name[index].innerText
                        },
                        success: function() {
                            history.go(0);
                        }
                    })
                }
            })



            // 保存重量
            weight.forEach(function(item, index) {
                    weightArr.push(parseFloat(item.innerText));
                })
                // console.log(weightArr);

            // 计算总价
            function productSum() {
                let sum = 0;
                let weight = 0;
                let youhui = 0;
                product_youhuiprice.forEach(function(item, index) {
                    if (icon_checked[index].checked) {
                        youhui += parseFloat(item.innerText) * num[index].value;
                    }
                })
                num.forEach(function(item, index) {
                    if (icon_checked[index].checked) {
                        weight += item.value * weightArr[index];
                    }
                })
                product_price.forEach(function(item, index) {
                    if (icon_checked[index].checked) {
                        sum += parseFloat(item.innerText);
                    }
                })
                product_sum.innerText = sum;
                s_money_span.innerText = sum;
                weightSum.innerText = weight;
                save.innerText = youhui;
            }

            // 数量输入框失去焦点时计算总价
            num.forEach(function(item, index) {
                    item.onblur = function() {
                        if (this.value < 1) {
                            this.value = 1;
                        }
                        this.value = Math.floor(this.value);
                        product_price[index].innerText = price[index] * this.value;
                        productSum();
                    }
                })
                // 保存单价
            product_price.forEach(function(item) {
                    price.push(parseFloat(item.innerText));
                })
                // console.log(price);
                // 点击-事件
            dec.forEach(function(item, index) {
                    item.onclick = function() {
                        if (num[index].value == 1) {
                            return;
                        }
                        num[index].value--;
                        product_price[index].innerText = price[index] * num[index].value;
                        if (icon_checked[index].checked) {

                            productSum();
                        }
                    }
                })
                // 点击+事件
            inc.forEach(function(item, index) {
                    item.onclick = function() {
                        num[index].value++;
                        product_price[index].innerText = price[index] * num[index].value;
                        if (icon_checked[index].checked) {

                            productSum();
                        }
                    }
                })
                // console.log(checkall)
                // console.log(icon_checked );

            checkall.checked = true;
            icon_checked.forEach(function(item, index) {
                item.checked = true;
                item.onclick = function() {

                    if (this.checked) {
                        this.checked = false;
                        this.style.backgroundPosition = '-10px -200px'
                    } else {
                        this.checked = true;
                        this.style.backgroundPosition = '-10px -183px'
                    }
                    select();
                    productSum();

                }
            })



            checkall.onclick = function() {
                // e.preventDefault();
                // console.log(5);

                this.checked = !this.checked;
                if (this.checked) {
                    icon_checked.forEach(function(item, index) {
                        item.checked = true;
                        item.style.backgroundPosition = '-10px -183px';
                    })
                    this.style.backgroundPosition = '-10px -183px'
                } else {
                    icon_checked.forEach(function(item, index) {
                        item.checked = false;
                        item.style.backgroundPosition = '-10px -200px';
                    })
                    this.style.backgroundPosition = '-10px -200px'
                }
                productSum();

            }

            function select() {
                // console.log(3);
                let flag = true;
                icon_checked.forEach(function(item, index) {
                    if (item.checked == false) {
                        flag = false;
                    }
                })
                checkall.checked = flag;
                if (flag) {
                    checkall.style.backgroundPosition = '-10px -183px'
                } else {
                    checkall.style.backgroundPosition = '-10px -200px'
                }
            }
            productSum();


        }
    })
}




getData();